package frame.laxcen.response;

import frame.laxcen.BaseFrame;
import frame.laxcen.dataobject.DataObject_0010_08;
import frame.laxcen.dataobject.DataObject_0010_11;
import frame.laxcen.exception.IllegalFrameFormatException;
import frame.laxcen.response.annotation.FrameFeature;
import frame.laxcen.util.FrameReader;

import java.util.HashMap;
import java.util.Map;

@FrameFeature(MessageType = 0b0010, Mid = 0x11)
public class Response_0010_11 extends BaseResponse {

    public Response_0010_11(BaseFrame baseFrame) throws IllegalFrameFormatException {

        super(baseFrame);

        getContentMap().putAll(explainToMap());
    }

    @Override
    protected Map<String, String> analyzeResponse(FrameReader reader) throws IllegalFrameFormatException {

        Map<String, String> result = new HashMap<>();

        switch(reader.readU8()) {

            case 0x00: result.put("写入结果", "写入成功"); break;
            case 0x01: result.put("写入结果", "天线端口参数错误"); break;
            case 0x02: result.put("写入结果", "选择参数错误"); break;
            case 0x03: result.put("写入结果", "写入参数错误"); break;
            case 0x04: result.put("写入结果", "CRC 校验错误"); break;
            case 0x05: result.put("写入结果", "功率不足"); break;
            case 0x06: result.put("写入结果", "数据区溢出"); break;
            case 0x07: result.put("写入结果", "数据区被锁定"); break;
            case 0x08: result.put("写入结果", "访问密码错误"); break;
            case 0x09: result.put("写入结果", "其他标签错误"); break;
            case 0x0a: result.put("写入结果", "标签丢失"); break;
            case 0x0b: result.put("写入结果", "读写器发送指令错误"); break;
        }

        reader.readP16((byte) 0x01, (s) -> result.put("写入失败字地址", Integer.toHexString(s)));

        return result;
    }

    public DataObject_0010_11 getDataObject() {

        return new DataObject_0010_11(getContentMap());
    }
}
